package com.example.demo.controller;

import com.example.demo.Entity.User;
import com.example.demo.utils.JWTUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
@RestController
public class LoginController {
    @GetMapping("/login")
    public String login(User user, HttpServletResponse response){
        //这里就不做数据库查询了

        //根据用户id生成token
        String token = JWTUtils.createToken(String.valueOf(user.getId()));
        //将token存入HTTP响应头中
        response.setHeader(JWTUtils.header,token);
        return user.toString();
    }

    @GetMapping("/find")
    public String find(){
        return "success";
    }
}
